$(function(){
    //pc端导航栏的点击，右侧信息的更换
    $('.side').on('click', '.j-item', function () {
        var eq = $(this).data('index');
        $(this).addClass('active').parents('.underline').siblings().find('.j-item').removeClass('active');
        $('.itemdetail').eq(eq).show().siblings().hide()
    });
    $(document).on('click','.slide',function () {
        var btn = $(this).find('b');
        btn.hasClass('j-add') ? btn.removeClass('icon-custom-add').addClass('icon-reduce') : btn.removeClass(
            'icon-reduce').addClass('icon-custom-add');
        var obj = $(this).parents('.questionbox').find('.answer');
        obj.slideToggle("slow")
    });
    $('.j-server').click(function () {
        var btn = $(this).find('i');
        btn.hasClass('icon-jiantouxia') ? btn.removeClass('icon-jiantouxia').addClass(
            'icon-jiantoushang') : btn.removeClass(
            'icon-jiantoushang').addClass('icon-jiantouxia');
        $(this).siblings('.servertoggle').slideToggle("slow");
        $(this).parents('.server-box ').siblings().find('.servertoggle').hide();
        $(this).parents('.server-box ').siblings().find('i').removeClass(
            'icon-jiantoushang').addClass('icon-jiantouxia')
    });
    //点击发送
    $('.sendbtn').click(function () {
        //声明添加客户反馈信息的参数
        var obj={
        name:$("#namePC").val()||$("#nameMobile").val(),
        phone:$("#phonePC").val()||$("#phoneMobile").val(),
        email:$("#emailPC").val()||$("#emailMobile").val(),
            content:$(".contentPC").val()||$("#contentMobile").val()
        };
        for(var i in obj){
            if(!obj[i]){
                layer.alert('请填写完整信息', {
                    skin: 'layui-layer-lan',
                    closeBtn: 0,
                    anim: 4
                });
                return false;
            }
        }
        addFeedback(obj);
    });
    $(document).on('click','.down-btn',function () {
        var id=$(this).data('id');
        var count=$(this).data('count');
        countDown(id,count);
    })
    // 查询下载中心的产品相关下载的内容
    queryLoad();
});
/**
 * 添加客戶反饋的信息
 */
function addFeedback(data){
    $.ajax({
        type:'POST',
        dataType:'json',
        url:'/rest/front/feedback/insertJson',
        data:data,
        success:function(){
                alert('发送成功，客户人员会及时联系您并给您答复！');
                setTimeout(function () {
                    location.reload();
                }, 100);
        }
    })
}
function countDown(id,count) {
    $.ajax({
        type:'POST',
        dataType:'json',
        url:'/rest/front/fileload/updateFileLoad',
        data:{id:id,loadAmount:count},
        success:function(){

        }
    })
}
/**
 * 查询全部产品的下载
 */
function queryLoad(){
    $.ajax({
        type:'GET',
        dataType:'json',
        url:'/rest/front/fileload/selectAllList',
        success:function(data){
            var downList=data.data,
                downPcHtml="",
                downMobileHtml="";
            $.each(downList,function(i,o){
                downPcHtml+='<div class="flex downbox middle"><img src="/'+o.image+'" alt="" class="pic">'+
                            '<div class="cell-main ml10"><div class="xl mb7">'+o.name+'</div><div class="f12 hui">'+o.introduce+'</div></div>'+
                            '<div class="down-btn f14" data-id="'+o.id+'" data-count="'+o.loadAmount+'"><a href="/'+o.fileUrl+'" >下载</a></div></div>';
                downMobileHtml+='<div class=" downbox center"><div class="xl item">'+o.name+'</div>'+
                                '<img src="/'+o.image+'" alt="" class="pic mb20"><div class="cell-main">'+
                                '<div class="l mb10">'+o.introduce+'</div></div><div class="down-btn xl" data-id="'+o.id+'" data-count="'+o.loadAmount+'"><a href="/'+o.fileUrl+'">下载</a></div></div>';
            });
            $(".downPc").append(downPcHtml);//pc端的渲染
            $(".downMobile").html(downMobileHtml);//移动端的渲染
        }
    })
}
(function(){
    $.ajax({
        type: 'GET',
        dataType: 'json',
        url: '/rest/front/question/selectQuestionList',
        success:function (data) {
            var list=data.data,html='';
            $.each(list,function (i, e) {
                html+='<div class="m-question ">\n' +
                    '<div class="dot xl mobile-title">'+e.name+'</div>';
              $.each(e.questionList,function (j, o) {
                  html+='<div class="questionbox pad5 lh2"><li class="flex mb10 slide bor1px">\n' +
                      '<div class="question f14 cell-main ">'+o.name+'</div>\n' +
                      '<b class="f18 iconfont icon-custom-add "></b></li><div class="answer hide f14 ">'+o.answer+'</div></div>'
              });
                html+='</div>';
            })
            $('.j-question').html(html)
        }
    })
})();